package com.atguigu.crowd.mvc.handler;

import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.atguigu.crowd.entity.Admin;
import com.atguigu.crowd.entity.Role;
import com.atguigu.crowd.mapper.RoleMapper;
import com.atguigu.crowd.service.api.AdminService;
import com.atguigu.crowd.util.CrowdUtil;

@Controller
public class TestHandler {

	@Autowired
	private AdminService adminService;

	Logger logger = LoggerFactory.getLogger(TestHandler.class);
	// 可以写一个实体类来进行发送
//	@ResponseBody
//	@RequestMapping("send/array/two.html")
//	public String testReceiveArrayTwo(@RequestParam("array") List<Integer> array) {
//		for (Integer number : array) {
//			System.out.println("number=" + number);
//		}
//		return "success";
//	}
	

	@ResponseBody
	@RequestMapping("send/array/three.html")
	public String testReceiveArrayThree(@RequestBody List<Integer> array, HttpServletRequest request) {

		boolean judgeResult = CrowdUtil.judgeRequestType(request);

		logger.info("judgeResult" + judgeResult);
		for (Integer number : array) {
			logger.info("number=" + number);
		}

		String a = null;

		System.out.println(a.length());

		return "success";
	}

	@ResponseBody
	@RequestMapping("send/array/one.html")
	public String testReceiveArrayOne(@RequestParam("array[]") List<Integer> array) {
		for (Integer number : array) {
			System.out.println("number=" + number);
		}
		return "success";
	}

	@RequestMapping("/test/ssm.html")
	private String testSsm(ModelMap modelMap, HttpServletRequest request) {

		boolean judgeResult = CrowdUtil.judgeRequestType(request);

		logger.info("judgeResult" + judgeResult);

		List<Admin> adminList = adminService.getAll();

		modelMap.addAttribute("adminList", adminList);

//		String a = null;

//		System.out.println(a.length());

		 System.out.println(10/0);

		return "target";
	}

}
